﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Luminoise
{
    public class Lerp : Module
    {
        static int instanceCount = 0;
        int instanceIndex;

        public Module Minimum { get; private set; }
        public Module Maximum { get; private set; }
        public Module Interpolant { get; private set; }

        public override string FunctionName
        {
            get { return "cl_lerp" + instanceIndex.ToString(); }
        }

        public override string GetCode()
        {
            return Minimum.GetCode() + Maximum.GetCode() + Interpolant.GetCode() +
@"#ifndef " + FunctionName.ToUpper() + @"
#define " + FunctionName.ToUpper() + @"

float " + FunctionName + @"(__global int *perm, Single3 input)
{
    return mix(" + Minimum.FunctionName + @"(perm, input), " + Maximum.FunctionName + @"(perm, input), " + Interpolant.FunctionName + @"(perm, input));
}

#endif

";
        }

        public Lerp(Module min, Module max, Module interpolant)
        {
            Minimum = min;
            Maximum = max;
            Interpolant = interpolant;

            instanceIndex = instanceCount;
            instanceCount++;
        }
    }
}
